#!/usr/bin/env python

class text:
	def __init__(self,string,**attributes):
		self.string = string

		# Set attributes to sane defaults.
		self.attributes = {
			'emphasis' : 0,		# 0:none, 1:em, 2:strong, 3:em+strong
		}

		# Override the default attributes with argument attributes.
		for name in attributes:
			self.attributes[name] = attributes[name]

	def html(self):
		emphasis = self.attributes['emphasis']

		if emphasis == 0:
			return self.string

		elif emphasis == 1:
			return '<em>%s</em>' % self.string

		elif emphasis == 2:
			return '<strong>%s</strong>' % self.string

		elif emphasis == 3:
			return '<em><strong>%s</strong></em>' % self.string

class paragraph:
	def __init__(self,*content,**attributes):
		# Content should be text or note.
		self.content = content
		
		# Set attributes to sane defaults.
		self.attributes = {
		}

		# Override the default attributes with argument attributes.
		for name in attributes:
			self.attributes[name] = attributes[name]

	def html(self):
		return '<p>%s</p>' % ''.join([c.html() for c in self.content])

class header:
	def __init__(self,level,*content,**attributes):
		self.level = level		# 1:h1, 2:h2, 3:h3, 4:h4, 5:h5

		# Content should be text or note.
		self.content = content

		# Set attributes to sane defaults.
		self.attributes = {
		}

		# Override the default attributes with argument attributes.
		for name in attributes:
			self.attributes[name] = attributes[name]

	def html(self):
		return "<h%i class='remarkable-header'>%s</h%i>" % (
			self.level,
			''.join([c.html() for c in self.content]),
			self.level,
		)

class list:
	def __init__(self,*items,**attributes):
		# Item should be listitem.
		self.items = items

		# Set attributes to sane defaults.
		self.attributes = {
			'ordered' : False,
		}

		# Override the default attributes with argument attributes.
		for name in attributes:
			self.attributes[name] = attributes[name]

	def html(self):
		if self.attributes['ordered']:
			return "<ol class='remarkable-ordered-list'>%s</ol>"\
				% ''.join([i.html() for i in self.items])

		return "<ul class='remarkable-undordered-list'>%s</ul>"\
			% ''.join([i.html() for  i in self.items])

class listitem:
	def __init__(self,*content,**attributes):
		# Content should be paragraph.
		self.content = content

		# Set attributes to sane defaults.
		self.attributes = {
		}

		# Override the default attributes with argument attributes.
		for name in attributes:
			self.attributes[name] = attributes[name]

	def html(self):
		return "<li class='remarkable-list-item'>%s</li>"\
			% ''.join([c.html() for c in self.content])

class document:
	def __init__(self,*content,**attributes):
		# Content should be header, paragraph, or list.
		self.content = content

		# Set attributes to sane defaults.
		self.attributes = {
			'title' : None,
			'subtitle' : None,
			'date' : None,
		}

		# Override the default attributes with argument attributes.
		for name in attributes:
			self.attributes[name] = attributes[name]

	def html(self,embeddable = True):
		if embeddable:
			return "<div class='remarkable-document'>%s</div>"\
				% ''.join([c.html() for c in self.content])

		raise Error() # Not implemented yet.
